﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.member;

namespace IFTRUE.Umbraco.Web.UserControls
{
    public partial class IFTRUE_Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["member"] != null)
            {
                divUserInfo.Visible = true;
                divLogin.Visible = false;
                lblUserInfo.Text = ((Member)Session["member"]).User.Name;
            }
            else
            {
                divUserInfo.Visible = false;
                divLogin.Visible = true;
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            Member member = Member.GetMemberFromLoginNameAndPassword(txtUserName.Text.Trim(), txtPwd.Text.Trim());
            if (member != null)
            {
                Session["member"] = member;
                divUserInfo.Visible = true;
                divLogin.Visible = false;
                lblUserInfo.Text = member.User.Name;
            }
            else
            {
                lblMsg.Text = "用户名或密码错误！";
            }
        }
    }
}